#include<iostream>
#include<algorithm>
#include<sstream>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int n;
int main()
{
	int t;
	cin >> t;
	string line;
	getline(cin, line);
	while (t--) {
		getline(cin, line);
		stringstream s(line);
		while (s >> arr[n])n++;
	}
	sort(arr, arr + n);
	int ans1 = 0, ans2 = 0;
	for (int i = 1; i < n; i++) {
		if (arr[i] == arr[i - 1]) {
			ans1 = arr[i];
		}
		else if (arr[i] == arr[i - 1] + 2) {
			ans2 = arr[i] - 1;
		}
	}
	cout << ans1 << " " << ans2 << endl;
	return 0;
}